﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.SEO.Model;
using com.SEO.DataAccess;
using com.SEO.Business;

namespace Helper.Bussiness
{
    public class UserManage : BaseManage
    {
        public int AddUserInfo(UserInfo info, string connName = ConnectionName)
        {

            UserCtrl ctrl = new UserCtrl();
            return ctrl.Insert(connName, info);
        }

        public int UpdateUserInfo(UserInfo info, string connName = ConnectionName)
        {

            UserCtrl ctrl = new UserCtrl();
            return ctrl.UpDate(connName, info);
        }

        public UserInfo GetUserInfoByID(string objectID, string connName = ConnectionName)
        {
            UserCtrl ctrl = new UserCtrl();
            List<UserInfo> lstUserInfo = ctrl.SelectAsList(connName, "UserID = '" + objectID + "'");
            if (lstUserInfo.Count > 0)
            {
                return lstUserInfo[0];
            }

            return null;
        }

        public List<UserInfo> GetUserByCondition(string strCondition, string connName = ConnectionName)
        {

            UserCtrl ctrl = new UserCtrl();
            return ctrl.SelectAsList(connName, strCondition);
        }

        public void DeleteUserInfo(UserInfo info, string connName = ConnectionName)
        {

            UserCtrl ctrl = new UserCtrl();
            ctrl.Delete(connName, info.UserId.ToString());

            SiteManage.CheckSite(info.SiteId);
        }

        public bool VerifyUser(string strUserName, string strUserPwd)
        {
            List<UserInfo> lstUsers = this.GetUserByCondition(" UserAccount = '" + strUserName + "' and UserPassword = '" + strUserPwd 
                + "' and UserType = 0");
            if (lstUsers.Count == 1)
            {
                return true;
            }

            return false;
        }
    }
}
